package com.itheima.job;

import java.util.ArrayList;
import java.util.Iterator;

public class Test03 {
    public static void main(String[] args) {
        ArrayList<Student> stuArray = new ArrayList<>();
        stuArray.add(new Student("张三",20,"男"));
        stuArray.add(new Student("李四",18,"女"));
        stuArray.add(new Student("王五",24,"男"));
        for (Student student : stuArray) {
            System.out.println(student);
        }

        int index = 0;
        int age  = 0;
        for (int i = 0; i < stuArray.size(); i++) {
            Student stu = stuArray.get(i);
            if (stu.getAge() > age) {
                age = stu.getAge();
                index = i ;
            }
        }
        stuArray.get(index).setName("小猪佩奇");
        for (Student student : stuArray) {
            System.out.println(student);
        }
    }

}

class Student{
    private String name;
    private Integer age;
    private String sex;

    public Student() {
    }

    public Student(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return
                "姓名:'" + name + '\'' +
                ", 年龄:" + age +
                ", 性别:'" + sex + '\'';
    }
}
